// pages/home/home.js
import {Home} from 'home-model.js'
var home = new Home();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: false,   
  },
  //微信生命周期函数：页面加载函数
  onLoad:function(){
    this._loadData();
  },

  //取得banner数据
  _loadData: function (callback){
    var that = this;
    //首页banner
    home.getBannerData((data)=>{
      that.setData({
        bannerArr: data,
      });
    });
    //首页主题
    home.getThemeData((data)=>{
      that.setData({
        themeArr: data,
        loadingHidden: true
      });
      
    });
    //最近新品
    home.getRecentData((data) => {
      that.setData({
        productsArr: data,
      });
    });
  },
  /*banner图片绑定事件 */
  onProductsItemTap:function(event){
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../product/product?id='+id,
    })
  },
  /*精选主题绑定事件 */
  onThemesItemTap:function(event){
    var id = event.currentTarget.dataset.id;
    var name = event.currentTarget.dataset.name;
    wx.navigateTo({
      url: '../theme/theme?id=' + id + '&name='+name,
    })
  },
  /*下拉刷新页面*/
  onPullDownRefresh: function () {
    this._loadData(() => {
      wx.stopPullDownRefresh()
    });
  },

  //分享效果
  onShareAppMessage: function () {
    return {
      title: '零食商贩 Pretty Vendor',
      path: 'pages/home/home'
    }
  }
})